2 using System.Collections.Generic;
5 using Microsoft.Xna.Framework;
6 using Microsoft.Xna.Framework.Graphics;
7 using Microsoft.Xna.Framework.Content;
8 using System.Security.Cryptography;
10 namespace SuperPolarity
12 class StandardShip : Ship
15 protected int ChangeRate;
16 protected int CurrentTime;
17 protected int AngleChangeProbability;
18 protected int BouncePadding;
19 protected float RotationFactor;
20 protected Random Random;
21 protected bool AddingAngle;
23 public StandardShip(SuperPolarity newGame) : base(newGame) {}
25 public override void Initialize(Texture2D texture, Vector2 position)
27 base.Initialize(texture, position);
29 var cryptoResult = new byte[4];
30 new RNGCryptoServiceProvider().GetBytes(cryptoResult);
33 AngleChangeProbability = 50;
37 RotationFactor = (float) (3 * Math.PI / 180);
38 Random = new Random(BitConverter.ToInt32(cryptoResult, 0));
44 public override void Magnetize(Ship ship, float distance, float angle)
46 if (ship.GetType() == typeof(MainShip)) {
47 base.Magnetize(ship, distance, angle);
51 public override void Update(GameTime gameTime)
53 CurrentTime += gameTime.ElapsedGameTime.Milliseconds;
65 protected void AutoMove()
67 float newAngle = Angle;
69 if (CurrentTime < ChangeRate)
74 if (Random.Next(AngleChangeProbability) == 2)
76 AddingAngle = !AddingAngle;
83 newAngle += (float) ( Random.NextDouble() * RotationFactor);
87 newAngle -= (float) (Random.NextDouble() * RotationFactor);
90 Velocity.X = (float) (MaxVelocity * Math.Cos(newAngle));
91 Velocity.Y = (float) (MaxVelocity * Math.Sin(newAngle));
94 protected void BounceBack()
96 if (Position.X + Width < -BouncePadding && Velocity.X < 0)
98 Velocity.X = -Velocity.X;
101 if (Position.Y + Height < -BouncePadding && Velocity.Y < 0)
103 Velocity.Y = -Velocity.Y;
106 if (Position.X > game.GraphicsDevice.Viewport.Width + BouncePadding && Velocity.X > 0)
108 Velocity.X = -Velocity.X;
111 if (Position.Y > game.GraphicsDevice.Viewport.Height + BouncePadding && Velocity.Y > 0)
113 Velocity.Y = -Velocity.Y;
117 public override void Collide(Actor other, Rectangle collision)
124 if (other.GetType() == typeof(MainShip))
130 if (other.GetType() == typeof(Bullet))
132 var theBullet = (Bullet)other;
133 TakeDamage(theBullet.Power);
137 protected override void Die()
139 ActorManager.CheckOut(this);
140 Renderer.CheckOut(this);
141 game.Player.AddScore(Value);
142 game.Player.AddMultiplier(1);